#!/bin/sh

set -e
set -x

PKGOS_IN_TMP=no
for i in $@ ; do
	case "${1}" in
	"--no-py3")
		echo "WARNING: --no-py3 is deprecated and always off."
		shift
		;;
	"--no-py2")
		echo "WARNING: --no-py2 is deprecated and always on."
		shift
		;;
	"--in-tmp")
		PKGOS_IN_TMP=yes
		shift
		;;
	*)
		;;
	esac
done

SRC_PKG_NAME=$(dpkg-parsechangelog -SSource)
PY_MODULE_NAME=$(echo ${SRC_PKG_NAME} | sed s/python-//)

PYTHON3S=$(py3versions -vr 2>/dev/null)

if [ "${PKGOS_IN_TMP}" = "yes" ] ; then
	TARGET_DIR=tmp
else
	TARGET_DIR=python3-${PY_MODULE_NAME}
fi
for pyvers in ${PYTHON3S}; do
	python${pyvers} setup.py install --install-layout=deb --root $(pwd)/debian/${TARGET_DIR}
done
rm -rf $(pwd)/debian/python*/usr/lib/python*/dist-packages/*.pth
rm -rf $(pwd)/debian/tmp/usr/lib/python*/dist-packages/*.pth
